package com.lancoo.znbkxx.teacher.aibkTestCoach.questionToMark

import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseActivity
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.Type
import com.lancoo.znbkxx.teacher.aibkTestCoach.questionToMark.adapter.MarkAnswerSheetParentAdapter
import kotlinx.android.synthetic.main.activity_mark_answer_sheet.*

/**
 * Created by Dadong on 2021/3/14
 * Describe:
 */
class AnswerSheetActivity : KBaseActivity(), View.OnClickListener {

    private var indexA: Int = 0
    private var indexB: Int = 0
    private var indexC: Int = 0


    private var mTypeList: MutableList<Type>? = null

    override fun setLayout(): Int {
        return R.layout.activity_mark_answer_sheet
    }

    override fun initView() {
        sbtn_back.setOnClickListener(this)
        initAnswerSheet()
    }

    override fun initData() {
        mTypeList = intent.extras?.getSerializable("TypeList") as MutableList<Type>
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.sbtn_back -> {
                finish()
            }
        }
    }

    private fun initAnswerSheet() {
        rv_answer_sheet.recycledViewPool.clear()
        rv_answer_sheet.setItemViewCacheSize(0)
        val manager = LinearLayoutManager(this)
        manager.orientation = LinearLayoutManager.VERTICAL
        rv_answer_sheet.layoutManager = manager
        val adapterParent = MarkAnswerSheetParentAdapter(
                this, mTypeList!!
        )
        rv_answer_sheet.adapter = adapterParent
        adapterParent.setClickParentListener(object : MarkAnswerSheetParentAdapter.OnClickParentListener {
            override fun onClick(
                    index_A: Int,
                    index_B: Int,
                    index_C: Int
            ) {
                indexA = index_A
                indexB = index_B
                indexC = index_C
                this@AnswerSheetActivity.setResult(101, Intent().apply {
                    putExtra("indexA", indexA)
                    putExtra("indexB", indexB)
                    putExtra("indexC", indexC)
                })
                finish()
            }

        })
    }
}